//
//  HTClassNavigationController.swift
//  QuitSmokingApp
//
//  Created by   on 2024/3/6.
//

import UIKit
import AutoInch

class HTClassNavigationController: UINavigationController {
    lazy var var_back: UIButton = {
        let var_button = UIButton()
        var_button.frame = CGRect(x: 0, y: 0, width: 24.auto(), height: 24.auto())
        var_button.setImage(UIImage(named: "icon_white_back"), for: .normal)
        var_button.onTap { [weak self] in
            self?.popViewController(animated: true)
        }
        return var_button
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        ht_navigationConfiguration()
        // Do any additional setup after loading the view.
    }
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.viewControllers.count > 0 {
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: self.var_back)
            viewController.hidesBottomBarWhenPushed = true
        } else {
            viewController.hidesBottomBarWhenPushed = false
        }
        super.pushViewController(viewController, animated: animated)
    }
    func ht_navigationConfiguration() {
        let var_appearance = UINavigationBarAppearance()
        var_appearance.configureWithOpaqueBackground()
        var_appearance.backgroundColor = HTClassTool.ht_getNavigationBack() // 设置背景颜色
        
        let var_navigationBarAppearance = UINavigationBarAppearance()
        var_navigationBarAppearance.configureWithOpaqueBackground()
        var_navigationBarAppearance.backgroundColor = HTClassTool.ht_getNavigationBack()
        var_navigationBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white, .font: UIFont.systemFont(ofSize: 20, weight: .medium) ]
        
        UINavigationBar.appearance().standardAppearance = var_appearance
        UINavigationBar.appearance().compactAppearance = var_navigationBarAppearance
        UINavigationBar.appearance().scrollEdgeAppearance = var_navigationBarAppearance
    }
}
